package com.pansoft.openplanet.activity.child;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;

import com.efounder.baseadapter.listview.CommonAdapter;
import com.efounder.baseadapter.listview.ViewHolder;
import com.efounder.utils.ResStringUtil;
import com.pansoft.openplanet.R;
import com.pansoft.openplanet.activity.TCBaseActivity;
import com.pansoft.openplanet.bean.CreateChildWalletBean;

import java.util.ArrayList;
import java.util.List;

/**
 * 备份子账号助记词
 * Created by will on 18-3-20.
 */

public class BackupChildMnemonicActivity extends TCBaseActivity implements View.OnClickListener {

    private GridView gridView;
//    private String number;
//    private String userName;
//    private String mnemonic;
//    private String address;
//    private String ethPublicKey;
    /** 是否是创建卡片冷钱包 **/
    private boolean isCardColdWallet;
    private CreateChildWalletBean childWalletBean;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.talk_chain_activity_backup_token_helper_child);

//        number = getIntent().getExtras().getString("number");
//        //userName = getIntent().getExtras().getString("userName");
//        mnemonic = getIntent().getExtras().getString("mnemonic");
//        address = getIntent().getExtras().getString("address");
//        ethPublicKey = getIntent().getExtras().getString("ethPublicKey");

        ImageView ivBack = (ImageView) findViewById(R.id.iv_back);
        ivBack.setOnClickListener(this);

        isCardColdWallet = getIntent().getBooleanExtra("isCardColdWallet", false);
        childWalletBean = (CreateChildWalletBean) getIntent().getSerializableExtra("childWalletBean");
        String mnemonic = childWalletBean.getMnemonic();
        List<String> mnemonics = new ArrayList<>();
        String[] arr = mnemonic.split("\\s+");
        for (String ss : arr) {
            mnemonics.add(ss);
        }
        TextView tvTitle = (TextView) findViewById(R.id.tv_title);
        tvTitle.setText(ResStringUtil.getString(R.string.openplanet_title_back_mnemonic));
        TextView tvAddress = (TextView) findViewById(R.id.tv_address);
        tvAddress.setText(childWalletBean.getWalletAddress());
        Button tvNext = (Button) findViewById(R.id.tv_next);
        tvNext.setOnClickListener(this);
        gridView = (GridView) findViewById(R.id.gv_token_helper);
        gridView.setSelector(new ColorDrawable(Color.TRANSPARENT));
        gridView.setAdapter(new MyTokenHelperAdapter(this, R.layout.talk_chain_item_token_helper, mnemonics));

    }

    @Override
    public void onClick(View view) {
        int id = view.getId();
        if (id == R.id.iv_back) {
            finish();
        } else if (id == R.id.tv_next) {
            Intent intent1 = new Intent(BackupChildMnemonicActivity.this, ChildTokenCheckActivity.class);
//            intent1.putExtra("wallet_avatar", getIntent().getStringExtra("wallet_avatar"));
//            intent1.putExtra("wallet_name", getIntent().getStringExtra("wallet_name"));
//            intent1.putExtra("chainId", getIntent().getIntExtra("chainId", IPAssetsConstant.CHAIN_ID_TURBOCHAIN));
//            intent1.putExtra("mnemonic", mnemonic);
//            intent1.putExtra("number", number);
//            intent1.putExtra("ethPublicKey", ethPublicKey);
//            intent1.putExtra("address", address);
//            intent1.putExtra("ethPrivateKey", getIntent().getStringExtra("ethPrivateKey"));

            intent1.putExtra("isCardColdWallet", isCardColdWallet);
            intent1.putExtra("childWalletBean",childWalletBean);
            BackupChildMnemonicActivity.this.startActivity(intent1);
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

    public class MyTokenHelperAdapter extends CommonAdapter<String> {
        public MyTokenHelperAdapter(Context context, int layoutId, List<String> datas) {
            super(context, layoutId, datas);
        }

        @Override
        protected void convert(ViewHolder viewHolder, String item, int position) {
            viewHolder.setText(R.id.tv_token_helper, position + 1 + "." + item);
        }
    }
}
